<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('工单明细列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <p>工单：</p>
<!--                                <input type="text" name="workOrderId"/>-->
                                <select id="workOrder" name="workOrder" style="width: 240px" class="form-control">
                                    <option th:each="list : ${workOrderList}" th:text="${list['workOrder']}" th:value="${list['id']}" th:field="*{workOrderId.id}"></option>
                                </select>
                            </li>
                            <li hidden>
                                <p>设备id：</p>
                                <input type="text" name="machineId"/>
                            </li>
                            <li hidden="hidden">
                                <p>bom Id：</p>
                                <input type="text" name="bomId"/>
                            </li>

                            <li>
                                <p>工序工单号：</p>
                                <input type="text" name="processWorkOrder"/>
                            </li>

                            <li>
<!--                                <p>工序</p>-->
<!--                                <input type="text" name="process"/>-->
                                <p>工序：</p>
                                <select name="process" th:with="type=${@dict.getType('work_process')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <p>状态：</p>
                                <select name="status" th:with="type=${@dict.getType('work_status')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="add()" shiro:hasPermission="workorder:detail:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="workorder:detail:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="workorder:detail:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="workorder:detail:export">
                    <i class="fa fa-download"></i> 导出
                 </a>
                <div class="btn-group-sm" id="toolbar" role="group">
                    <a class="btn btn-success" onclick="changeStatus(2)" style="background-color: green"  shiro:hasPermission="workorder:detail:add">
                        <i class="fa fa-edit"></i> 开工
                    </a>
                    <a class="btn btn-warning" onclick="changeStatus(3)" shiro:hasPermission="workorder:detail:add">
                        <i class="fa fa-edit"></i> 暂停
                    </a>
                    <a class="btn btn-danger multiple disabled" onclick="changeStatus(4)" shiro:hasPermission="workorder:detail:add">
                        <i class="fa fa-edit"></i> 故障
                    </a>
                    <a class="btn btn-success" onclick="changeStatus(5)" shiro:hasPermission="workorder:detail:add">
                        <i class="fa fa-edit"></i> 完工
                    </a>
                    <a class="btn btn-danger multiple disabled" style="background-color: red" onclick="changeStatus(6)" shiro:hasPermission="workorder:detail:add">
                        <i class="fa fa-edit"></i> 作废
                    </a>
                </div>
            </div>


            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('workorder:detail:edit')}]];
        var removeFlag = [[${@permission.hasPermi('workorder:detail:remove')}]];
        var prefix = ctx + "WorkOrder/detail";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add/{id}",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "工单明细",
                queryParams:queryParams,
                columns: [{
                    checkbox: true
                },
                {
                    field : 'detailId', 
                    title : '工单明细表',
                    visible: false
                },
                {
                    field : 'workOrderId', 
                    title : '工单主表id',
                    visible: false
                },
                {
                    field : 'workOrder',
                    title : '工单'
                },
                {
                    field : 'machineId', 
                    title : '设备id',
                    visible: false
                },
                {
                    field : 'machineName',
                    title : '设备'
                },
                {
                    field : 'bomId', 
                    title : 'bom Id',
                    visible: false
                },
                {
                    field : 'bomName',
                    title : 'bom'
                },
                {
                    field : 'processWorkOrder',
                    title : '工序工单号'
                },
                {
                    field : 'process', 
                    title : '工序',
                    formatter:getProcess
                },
                {
                    field : 'status', 
                    title : '状态',
                    formatter:getStatus
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.detailId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.detailId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        function queryParams(params) {
            var search = $.table.queryParams(params);
            search.workOrderId = $("#workOrder").val();
            return search;
        };
        function getProcess(value, row, index) {
            var val = [[${@dict.getType('work_process')}]]
            for(var i = 0;i<val.length;i++){
                if(val[i].dictSort == value){
                    console.log(val[i].dictLabel)
                    return val[i].dictLabel;
                    break;
                }
            }
        }
        function getStatus(value, row, index) {
            var val = [[${@dict.getType('work_status')}]]
            for(var i = 0;i<val.length;i++){
                if(val[i].dictSort == value){
                    console.log(val[i].dictLabel)
                    return val[i].dictLabel;
                    break;
                }
            }
        }
        function add() {
            var workOrder = $("#workOrder option:selected").val();
            $.operate.add(workOrder);
        };
        function changeStatus(status) {
            table.set();
            var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
            if (rows.length != 1) {
                $.modal.alertWarning("请选择一条记录");
                return;
            }
            var font;
            if(status == 2){
                font = "开工"
            }else if(status == 3){
                font = "暂停"
            }else if(status == 4){
                font = "故障"
            }
            else if(status == 5){
                font = "完工"
            }else if(status == 6){
                font = "作废"
            }
            var id = rows[0];
            console.log(id)
            $.modal.confirm("确认要"+font+"选中的条数据吗?", function() {
                $.ajax({
                    url: prefix+"/changeStatus",
                    type:"POST",
                    data:{
                        detailId:id,
                        status:status
                    },
                    success: function (result) {
                        if (result.code == web_status.SUCCESS) {
                            $.modal.closeAll();
                            $.modal.alertSuccess(result.msg);
                            $.table.refresh();
                        } else if (result.code == web_status.WARNING) {
                            layer.close(index);
                            $.modal.enable();
                            $.modal.alertWarning(result.msg)
                        } else {
                            layer.close(index);
                            $.modal.enable();
                            $.modal.alertError(result.msg);
                        }
                    }
                })
            });
        }
    </script>
</body>
</html>